package com.globallogic.vkulyk.SSHTool;

import org.junit.runner.RunWith;
import org.junit.*;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.core.classloader.annotations.*;
import org.powermock.api.mockito.PowerMockito;
import org.mockito.*;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ CLIHandler.class })
public class Unit_CLIHandler extends SSHToolTester {

	@Before
	public void setup() {
		setVarsFromPropertiesFile("testData/testing.properties");

	}

	@Test
	public void shouldInstantiateUserDataModeHandlerAndCallRun_whenEnterUserModeDataFromCLI()
			throws Exception {
		// given
		CLIUserDataModeHandler mockedCLIUserDataModeHandler = Mockito
				.mock(CLIUserDataModeHandler.class);
		PowerMockito.whenNew(CLIUserDataModeHandler.class)
				.withArguments(Mockito.any(String[].class))
				.thenReturn(mockedCLIUserDataModeHandler);
		String[] expectedArgs = {
				user + ":" + password + "@" + host + ":" + port, "-c", command };

		// when
		new CLIHandler().run(expectedArgs);

		// then
		PowerMockito.verifyNew(CLIUserDataModeHandler.class).withArguments(
				Mockito.eq(expectedArgs));
		Mockito.verify(mockedCLIUserDataModeHandler).run();
	}

	@Test
	public void shouldInstantiateTargetModeHandlerAndCallRun_whenEnterTargetDataFromCLI()
			throws Exception {
		// given
		CLITargetModeHandler mockedCLITargetModeHandler = Mockito
				.mock(CLITargetModeHandler.class);
		PowerMockito.whenNew(CLITargetModeHandler.class)
				.withArguments(Mockito.any(String[].class))
				.thenReturn(mockedCLITargetModeHandler);
		String[] expectedArgs = { "-f", targetsFile, "-t", target };

		// when
		new CLIHandler().run(expectedArgs);

		// then
		PowerMockito.verifyNew(CLITargetModeHandler.class).withArguments(
				Mockito.eq(expectedArgs));
		Mockito.verify(mockedCLITargetModeHandler).run();
	}

}
